<html>
<head>
<meta name="viewport"
	content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta charset="utf-8" />
<#include "include/lib.ftl">
<style>
#container {
	height: 100%;
}
#login {
	width: 100%;
	margin-top: 15px;
}
h1 {
	text-align: center;
}
#cen {
	margin-top: 20%;
	display: none;
}
</style>
</head>
<body>
<div id="dialog" class="col-md-3 col-md-offset-9 col-sm-12"></div>
	<div id="container" class="container">
		<div id="cen">
			<div class="col-md-4 col-sm-0"></div>
			<div id="con" class="col-md-4 col-sm-12">
				<h1>XXXX登陆</h1>
				<form role="form">
					<!-- 把表单控件放在这个.form-group的里面，可以获取最佳间距 -->
					<div class="form-group">
						<label for="username">账户名:</label> <input type="text"
							class="form-control" id="username" placeholder="请输入账户名" />
					</div>
					<div class="form-group">
						<label for="password">密码:</label> <input type="password"
							class="form-control" id="password" placeholder="请输入密码" />
					</div>
					<div class="submit">
						<a id="login" class="btn btn-primary">登&nbsp;&nbsp;陆</a>
					</div>
				</form>
			</div>
			<div class="col-md-4 col-sm-0"></div>
		</div>
	</div>




</body>

<script>
	$(function() {
		$("#cen").css("display", "block");
		var t = setTimeout(addAni, 100);
	});

	function addAni() {
		$("#cen").addClass("animated bounceInDown");
	}

	$("#login").click(function() {
		if (validateParam()) {
			login();
		}
	});

	function login() {
		var username = $("#username").val();
		var password = $("#password").val();
		$.ajax({
			url : "${path}/user/login.ajax",
			type : "post",
			dataType : "json",
			data : {
				username : username,
				password : password
			},
			success : function(data) {
				if ("SUCCESS" == data.result) {
					window.location.href = "${path}/report/home.htm";
				} else {
					var dialog = new Dialog(data.msg, "warning")
					dialog.obj = "#dialog";
					dialog.show();
				}
			},
			error : function(e) {
				var dialog = new Dialog("服务器发生未知的错误，请稍后再试", "danger")
				dialog.obj = "#dialog";
				dialog.show();
				
			}
		});
	}

	function validateParam() {
		var username = $("#username").val();
		var password = $("#password").val();
		if (username.trim().length == 0) {
			var dialog = new Dialog("用户名不能为空", "warning")
			dialog.obj = "#dialog";
			dialog.show();
			return false;
		} else if (password.trim().length == 0) {
			var dialog = new Dialog("密码不能为空", "warning")
			dialog.obj = "#dialog";
			console.log(dialog);
			dialog.show();
			return false;
		}
		return true;
	}
</script>
</html>
